<?php

/*
 * ************************************************* 
 * Created on :2012-5-2 21:46:11
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

class Forumc {

    static $table = "forum";

    public static function add($title, $content, $remark, $parentid = NULL) {
        if ((empty($title) && empty($parentid)) || empty($content))
            return false;
        $data = array("parent_id" => $parentid, "title" => $title, "content" => $content,
            "userid" => $GLOBALS['user']->userid, "createtime" => date("Y-m-d H:i:s"),
            "remark" => $remark, "show" => "Y");
        return DB::Insert(self::$table, $data);
    }

    public static function del($id) {
        if (empty($id))
            return false;
        return DB::Update(self::$table, $id, array("show" => "N"));
    }

    public static function getone($id) {
        return DB::GetTableRow(self::$table, array("id" => $id));
    }

    public static function getreplayscount($id) {
        $r = DB::LimitQuery(self::$table, array("condition" => array("parent_id" => $id), "select" => "count(*) as count", "one" => true));
        return $r['count'];
    }

    public static function getreplys($id, $offset, $size, $order = "id asc") {
        return DB::LimitQuery(self::$table, array("condition" => array("parent_id" => $id), "offset" => $offset, "size" => $size, "order" => "ORDER BY " . $order));
    }

    public static function postscount($key) {
        $condition = array();
        if (!empty($key)) {
            $condition[] = "title like '%$key%' or content like '%$key%'";
        }
        $condition["parent_id"] = NULL;
        $r = DB::LimitQuery(self::$table, array("condition" => $condition, "one" => true, "select" => "count(*) as count"));
        return $r['count'];
    }

    public static function posts($key, $offset, $size) {
        $condition = array();
        if (!empty($key)) {
            $condition[] = "title like '%$key%' or content like '%$key%'";
        }
        $condition["parent_id"] = NULL;
        return DB::LimitQuery(self::$table, array("condition" => $condition, "offset" => $offset, "size" => $size, "ORDER BY id desc"));
    }

}

/* End of file forum */


